package zhongbo.java.air.monitor.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.monitor.model.FlightActivityDaily;
import zhongbo.java.air.monitor.service.IFlightActivityDailyService;

import java.util.Date;
import java.util.List;

/**
 * 说明：
 *
 * @author 钟波dellNotebook
 * @since 2025年04月08日 星期二 03:35:26
 */
@RestController
@RequestMapping("/flightDaily")
@Api(tags = "航迹监控操作")
public class FlightActivityDailyController {

    @Autowired
    private IFlightActivityDailyService flightActivityDailyService;

    @ApiOperation("查询当天分组统计结果")
    @GetMapping("/getDailyStats")
    public ResultVo<List<FlightActivityDaily>> getDailyStats(String date) {
        // 如果不传, 则默认查当天的统计结果
        if (StrUtil.isBlank(date)) {
            date = DateUtil.today();
        }
        List<FlightActivityDaily> dailyList = flightActivityDailyService.getDailyStats(date);
        return ResultVo.ok(dailyList);
    }
    // todo 今日周二待做, 标准crud接口(包括分页)
    @PostMapping("/add")
    @ApiOperation("新增航迹")
    ResultVo<FlightActivityDaily> add(@RequestBody FlightActivityDaily flightActivityDaily){
        if (flightActivityDaily == null || flightActivityDaily.equals("")){
            return ResultVo.error("传入数据为空");
        }

            int i = flightActivityDailyService.addFlightActivityDaily(flightActivityDaily);
            if (i <= 0){
                return  ResultVo.wrong(404,"添加失败");
            }
            return ResultVo.ok(flightActivityDaily);
    }
    @GetMapping("/delete")
    @ApiOperation("删除信息")
    ResultVo<FlightActivityDaily> delete(String id){
        if (id == null || id.equals("")){
            return ResultVo.error("id为空");
        }
        FlightActivityDaily flightActivityDaily = flightActivityDailyService.selectById(id);
        if (flightActivityDaily == null || flightActivityDaily.equals("")){
            return ResultVo.error("无该信息");
        }
        flightActivityDailyService.deleteFlightActivityDaily(id);

        return ResultVo.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新信息")
    ResultVo<FlightActivityDaily> update(@RequestBody FlightActivityDaily flightActivityDaily){
        if (flightActivityDaily == null || flightActivityDaily.equals("")){
            return ResultVo.error("数据信息为空");
        }
        int i = flightActivityDailyService.updateFlightActivityDaily(flightActivityDaily);
        if (i <= 0){
            return ResultVo.error("更新失败");
        }
        return ResultVo.success();
    }

    @GetMapping("/datil")
    @ApiOperation("航迹详细信息")
    ResultVo<FlightActivityDaily> selectById(String id){
        if (id == null || id.equals("")){
            return ResultVo.error("id为空");
        }
        FlightActivityDaily flightActivityDaily = flightActivityDailyService.selectById(id);
        if (flightActivityDaily == null || flightActivityDaily.equals("")){
            return ResultVo.error("查询失败");
        }
        return ResultVo.ok(flightActivityDaily);
    }
    @GetMapping("/page")
    @ApiOperation("Date分页查询")
    ResultVo<PageVo<FlightActivityDaily>> page(String dateStr, Integer pageNumber, Integer pageSize){
        PageVo<FlightActivityDaily> pageVo = flightActivityDailyService.page(dateStr,pageNumber,pageSize);
        return ResultVo.ok(pageVo);
    }
}
